<?php


namespace App\Models;


use Illuminate\Support\Facades\DB;

class Course extends BaseModel
{
    protected $table = 'course';

    public static function getRate($input,$date)
    {
        $list = self::get()
            ->toArray();
        $date_array = get_days($date, 6);
        foreach($list as $key=>&$val){
            $where = StoreDeal::userWhere($input,$date);
            $where[] = ['course_id', '=', $val['id']];
            $now_where[] = ['deal_time', '=', $date];
            $now_where = array_merge($where,$now_where);
            $sum = LearnCourse::where($now_where)->sum('num');

            $last_where[] = ['deal_time', '=', uyestoday($date)];
            $last_where = array_merge($where, $last_where);
            $last_sum = LearnCourse::where($last_where)->sum('num');
            $val['rate'] = self::ringRate($sum, $last_sum);

            $sum = [];
            foreach($date_array as $v){
                $day_where[] = ['deal_time', '=', $v];
                $day_where = array_merge($where,$day_where);
                $sum[] = LearnCourse::where($day_where)->sum('num');
            }
            $val['line'] = self::oneLine($date_array,$sum);
        }
        return $list;
    }

}